package org.cheetah.spring.xml.factory;

import java.util.List;

import org.cheetah.Predicate;
import org.cheetah.activities.Activity;
import org.cheetah.activities.If;
import org.springframework.beans.factory.config.AbstractFactoryBean;

public class IfProcessorFactoryBean extends AbstractFactoryBean<If> {
	private String condition;

	private Predicate predicate;

	private List<?> then;

	private List<?> _else;

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public void setPredicate(Predicate predicate) {
		this.predicate = predicate;
	}

	public void setThen(List<?> then) {
		this.then = then;
	}

	public void setElse(List<?> _else) {
		this._else = _else;
	}

	public Class<?> getObjectType() {
		return If.class;
	}

	protected If createInstance() throws Exception {
		If instance = new If();
		instance.setCondition(condition);
		instance.setPredicate(predicate);

		instance.setThen(then.toArray(new Activity[0]));
		instance.setElse(_else == null ? null : _else.toArray(new Activity[0]));

		return instance;
	}
}
